<template>
  <div>
    <div class="nav bg-theme color-f text-l">
      <div style="display:flex;flex:2;">
        <i class="iconfont icon-fanhui font19 pl08 iback" @click="goBack"></i>
        <!-- 详情进入 -->
        <span class="font19 ml16">
          递交
        </span>
      </div>
    </div>

    <div>
      <van-field v-model="message" rows="5" autosize label="" type="textarea" placeholder="请输入您的意见" />
      <div @click="addOpnion" class="addOp">
        <i class="iconfont icon-add color-9 font14 mr5"></i>
        <span class="font14 color-3 oncenter">常用意见</span>
      </div>
      <van-popup v-model="opnionPicker" position="bottom">
        <van-picker show-toolbar :columns="opnionList" @confirm="opnionConfirm" @cancel="opnionPicker = false" />
      </van-popup>
      <div class="bge"></div>

      <!-- 选择抄送人员 -->
      <div v-if="hasCopy" class="copyDiv" @click="toSelectCopy">
        <div class="color-8 font12">选择抄送人员：</div>
        <div style="margin-top:5px;" class="color-8 font13">
          <span v-for="(item, index) in copyList" :key="item.id">
            <span class="font13 color-8" v-if="index == 0">{{
              item.name
            }}</span>
            <span class="font13 color-8" v-else>,{{ item.name }}</span>
          </span>
        </div>
      </div>

      <div v-if="hasCopy" class="bge"></div>
      <div class="decisionList">
        <van-radio-group v-model="decisionRadio">
          <van-radio v-for="item in decisions" :key="item.id" :name="item.id" class="font14 ht40"
            @click="decisionClick(item.id)">
            {{ htmlDecode(item.decisionName) }}
            <div v-if="decisionRadio == item.id && !selectData" class="color-9 font14">
              {{ uListName }}
            </div>
            <div v-if="decisionRadio == item.id && selectData" class="color-9 font14">
              <div v-if="selectData.length > 0 && selectData.length < 6" class="color-9 font14">
                <span v-for="(item2, index2) in selectData" :key="item2.id">
                  <span v-if="index2 == 0">{{ item2.name }}</span>
                  <span v-else>,{{ item2.name }}</span>
                </span>
              </div>
              <div v-else-if="selectData.length >= 6" class="color-9 font14">
                <span v-for="(item3, index3) in selectDataover" :key="item3.id">
                  <span v-if="index3 == 0">{{ item3.name }}</span>
                  <span v-else-if="index3 < 6">,{{ item3.name }}</span>
                  <span v-else>等{{ selectData.length }}人</span>
                </span>
              </div>
              <span v-else>{{ selectData.name }}</span>
            </div>
            <div v-if="decisionRadio == item.id && decision == 'end'&&!isNotSJYPChengban()" class="color-9 font14">
              当前决策项无需候选人
            </div>
          </van-radio>
        </van-radio-group>
      </div>

      <div class="pof-btn">
        <van-button @click="submitClick" :loading="isSubmit" loading-text="提交中" block
          class="bg-theme color-f ht46 font17">提交</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast,Notify,Dialog } from 'vant'
import { getOrgAndUser } from '@/api/public'
import { getSrqrRequest,verifyPersonDepartmentExists } from "@/api/dictapi";
import { mapGetters } from 'vuex'
import util from "@/assets/js/public";
export default {
  computed: {
    ...mapGetters(['user'])
  },
  data() {
    return {
      message: '', // 意见
      decisionName: '', // 决策项名称
      opnionPicker: false,
      opnionList: ['同意', '不同意', '请审批', '请修改', '已阅'],
      params: {}, // 上个页面传过来的数据
      decisions: [], // 决策项
      decisionRadio: '',
      isSubmit: false, // 按钮是否处于提交状态
      isMore: false, // 是否多选
      uList: [], // 人
      uListName: '',
      copyDecision: {}, // 抄送决策项---》是指决策项的类型是否为抄送决策项
      hasCopy: false, // 当前选中的决策项是否含有抄送
      copyList: [], // 抄送所选的人
      selectData: null, // 已经在选人页面选过的人或者组织
      decision: '',
      selectDataover: null, //
      pmInsType: '',
      getDecisionsUrl: '',
      getDecisionsParams: '',
      getUserUrl: '',
      getUserParams: '',
      tosubmintUrl: '',
      tosubmintParams: '',
      normalDecision: {},

      /// 有承办
      cityDecision: null,      /// 地市承办 市公司决策结果
      provinceDecision: null,  /// 省公司承办 省公司决策结果
      isCityOrProvince: null,   /// 区分 地市承办 city、省公司承办 province
      otherParams:''
    }
  },

  created() {


  },

  activated() {
    //暂时放在这里，防止返回详情后再进入审批页面没有决策项
    //    console.log('传入的接口和参数11111111111' + JSON.stringify(this.$route.params));
    let query=JSON.parse(localStorage.getItem('submitPageParam'));
    this.params = query
    this.getDecisionsUrl = this.params.getDecisionsUrl
    this.getDecisionsParams = this.params.getDecisionsParams
    this.getUserUrl = this.params.getUserUrl
    this.getUserParams = this.params.getUserParams
    this.otherParams = this.params.otherParams
    this.tosubmintUrl = this.params.tosubmintUrl
    this.tosubmintParams = this.params.tosubmintParams
    
    this.cityDecision = this.params.cityDecision;
    this.provinceDecision = this.params.provinceDecision
    this.isCityOrProvince = this.params.isCityOrProvince
    console.log('AAAAAAAAAAAAAA' + this.params.cityDecision)
    this.getDecisions()
    if (
      localStorage.getItem('searchParams') != '{}' &&
      !!localStorage.getItem('searchParams')
    ) {
      this.params = JSON.parse(localStorage.getItem('searchParams'))
      this.params = Object.assign({ ...this.params.oldParams }, this.params)
      this.decisionRadio = this.params.currentDecision
      localStorage.setItem('searchParams', '{}')
    }
    if (
      localStorage.getItem('searchKeyword') != '{}' &&
      !!localStorage.getItem('searchKeyword')
    ) {
      if (this.params.isCopy == 'false') {
        console.log('AAAAAAAAAAAAAA')
        this.selectData = JSON.parse(localStorage.getItem('searchKeyword'))
        if (this.selectData.length > 6) {
          this.selectDataover = this.selectData.slice(0, 7)
          //  console.log('AAAAAAAAAAAAAA'+JSON.stringify(this.selectDataover))
          //  console.log('BBBBBBBBBBBBBBB'+JSON.stringify(this.selectData))
        }
      } else if (this.params.isCopy == 'true') {
        console.log('BBBBBBBBBBBBB')
        this.copyList = JSON.parse(localStorage.getItem('searchKeyword'))
        this.selectData = this.params.selectPeople
      }
      localStorage.setItem('searchKeyword', '{}')
    }
  },
  methods: {


    goBack() {
      this.params = {};
      this.selectData = null;
      this.decisions = [];
      this.decisionRadio = '';
      this.uList = [];
      this.uListName = '';
      this.copyDecision = {};
      this.hasCopy = false;
      this.copyList = [];
      this.decision = '';
      this.$router.back(-1) //返回上一页
      this.normalDecision = {};
    },

    isDecisions(outcomeName) {
      return outcomeName.indexOf("归档") != -1
        || outcomeName.indexOf("请领导审批") != -1
        || outcomeName.indexOf("同意,请办理") != -1
        || outcomeName.indexOf("请政企部审批") != -1
        || outcomeName.indexOf("请省标前决策管理员审批") != -1
        || outcomeName.indexOf("协办") != -1
        || outcomeName.indexOf("转办") != -1
        || outcomeName.indexOf("请地市交付经理会签") != -1
        || outcomeName.indexOf("请市公司标前决策管理员处理") != -1
        || outcomeName.indexOf("请省公司会签") != -1
        || outcomeName.indexOf("同意") != -1
        || outcomeName.indexOf("请省公司政企客户部标前决策管理员审批") != -1;
        
    },
     isDecisionsXFFCD(outcomeName) {
            return outcomeName.indexOf("同意,起草人确认归档") != -1
                || outcomeName.indexOf("确认归档") != -1
                || outcomeName.indexOf("请行业拓展中心主管审批") != -1
                || outcomeName.indexOf("请省标前决策管理员审批") != -1
                || outcomeName.indexOf("请省公司会签") != -1
                || outcomeName.indexOf("转办") != -1
                || outcomeName.indexOf("会签通过") != -1
                || outcomeName.indexOf("会签不通过") != -1
                || outcomeName.indexOf("请交付经理预定级") != -1
                || outcomeName.indexOf("请市公司标前决策管理员审批") != -1
                || outcomeName.indexOf("请政企部审批(市公司)") != -1
                || outcomeName.indexOf("请领导审批") != -1
                || outcomeName.indexOf("请交付经理预定级") != -1
                || outcomeName.indexOf("请行业运营室主管审批") != -1
                || outcomeName.indexOf("请行业运营室协办") != -1
                ;
        },
    /// 有承办 模块的选择判断
    checkDecision(value) {

      var pmInsType = this.getDecisionsParams.kv.processType;
      if (!(pmInsType == 'XE' || pmInsType == 'XFFB' || pmInsType == 'XFFA' || pmInsType == 'XFF' || pmInsType == 'XF'|| pmInsType == 'XFFC' || pmInsType == 'XFFD')) {
        return true;
      }
      let isXFFCD = pmInsType == 'XFFC'|| pmInsType == 'XFFD';
      var isCityOrProvince = this.isCityOrProvince;
      if (isCityOrProvince != "city" && isCityOrProvince != "province") {
        return true;
      }
      var cityDecision = this.cityDecision;
      var provinceDecision = this.provinceDecision;
      var outcomeName = value;

      
      if (isCityOrProvince == "city") {
        console.log('⭕️⭕️⭕️⭕️⭕️⭕️ result：' + isCityOrProvince + '--' + cityDecision + '--' + provinceDecision + '--' + outcomeName)
        if (!cityDecision) {
          Notify({ type: 'warning', message: '决策项与市公司决策结果不一致,无法流转' })
          return false;
        }
        else if (cityDecision == "同意" && !provinceDecision) {
          if(isXFFCD && this.isDecisionsXFFCD(outcomeName)){
            return true
          }else if (!isXFFCD && this.isDecisions(outcomeName)) {
            return true
          }else {
            Notify({ type: 'warning', message: '决策项与市公司决策结果不一致,无法流转' })
            return false
          }
        } 
        else if (cityDecision == "不同意" && !provinceDecision) {
          
          if (outcomeName.indexOf("不同意") != -1) {
            return true;
          }
          else {
            Notify({ type: 'warning', message: '决策项与市公司决策结果不一致,无法流转' });
            return false
          }
        }
      }

      if (isCityOrProvince == "province") {
        if (!provinceDecision) {
          Notify({ type: 'warning', message: '决策项与市公司决策结果不一致,无法流转' });
          return false
        } else if (provinceDecision == "同意") {
          if(isXFFCD && this.isDecisionsXFFCD(outcomeName)){
            return true
          }else if (!isXFFCD && this.isDecisions(outcomeName)) {
            return true
          }else {
            Notify({ type: 'warning', message: '决策项与市公司决策结果不一致,无法流转' });
            return false
          }
        } else if (provinceDecision == "不同意") {
          if (outcomeName.indexOf("不同意") != -1) {
            return true;
          }
          else {
            Notify({ type: 'warning', message: '决策项与市公司决策结果不一致,无法流转' });
            return false
          }
        }
      }

      return true;
    },
    isNotSJYPChengban(){
      var pmInsType = this.getDecisionsParams.kv.processType;
      var location = this.getDecisionsParams.kv.location;
      if ((pmInsType == 'YPL'||pmInsType == 'YPU') &&(location==="dict.countersignProvince"||location==="dict.countersignManager"
          ||location==="dict.countersignProvinceUp"||location==="dict.province"||location==="dict.countersignManagerUp")) {
        return true;
      }
    },
    // 获取决策项
    getDecisions() {
      Toast.loading({
        message: "加载中...",
        forbidClick: false,
      });

      getSrqrRequest(this.getDecisionsUrl, this.getDecisionsParams)
        .then((res) => {
          Toast.clear();
          this.decisions = [];

          if (res.data.data && res.data.data.length > 0) {
            // 判断是否有---> 抄送决策项
            // 判断是从待办还是待阅过来的--待办过来的判断decisionId,待阅过来的判断decisionName

            for (var i in res.data.data) {
              if ((res.data.data[i].decisionId.indexOf('copy') > -1)&&this.params.type != 'toRead'){
                // 存在抄送决策项
                this.copyDecision = res.data.data[i]
              } else {
                this.decisions.push(res.data.data[i])
              }
            }

            // if (this.params.type == 'toRead') {
            //   for (var i in res.data) {
            //     if (res.data[i].decisionName.indexOf('copy') > -1) {
            //     } else {
            //       this.decisions.push(res.data[i])
            //     }
            //   }
            // }
            // for (var i in this.decisions) {
            //   if (this.decisions[i].id == this.decisionRadio) {
            //     this.message = this.decisions[i].decisionName
            //     var config = this.decisions[i].decisionConfig.replace(
            //       /&quot;/g,
            //       '"'
            //     )
            //     config = JSON.parse(config)
            //     for (var j in config) {
            //       if (
            //         config[j].type == 'activiType' &&
            //         config[j].typeValue == 'copy'
            //       ) {
            //         // 判断当前决策项是否含有抄送
            //         this.hasCopy = true
            //         // this.copyList = [];
            //       }
            //     }
            //   }
            // }
          }
        }).catch(err => {
          Toast.clear();
          console.log(err);
        });
    },

    // 添加常用意见
    addOpnion() {
      this.opnionPicker = true
    },

    opnionConfirm(value) {
      this.message = value
      this.opnionPicker = false
    },
    //处理转义字符
    htmlDecode(str) {
      var arrEntities = { lt: "<", gt: ">", nbsp: " ", amp: "&", quot: '"' };
      return str.replace(/&(lt|gt|nbsp|amp|quot);/gi, function (all, t) {
        return arrEntities[t];
      });
    },
    decisionClick(name) {
      this.uListName = ''
      this.selectData = null
      this.copyList = []
      this.hasCopy = false
      for (var i in this.decisions) {
        if (this.decisions[i].id == name) {
          this.message = this.decisions[i].opinion
          this.decision = this.decisions[i].decisionId
          this.decisionName = this.decisions[i].decisionName;
          var decisionName = this.decisions[i].decisionName;
          if (!this.checkDecision(decisionName)) {
            return;
          }
          // 根据决策项判断是否多选，是否必须选人
          var config = this.decisions[i].decisionConfig.replace(/&quot;/g, '"')
          config = JSON.parse(config)
          for (var j in config) {
            if (config[j].type == 'activiType' && config[j].typeValue == 'copy') {
              // 判断当前决策项是否含有抄送
              this.hasCopy = true
            }
          }
          if ((this.decisions[i].decisionId == 'end' || this.decisions[i].decisionId.indexOf('end') > -1)&&!this.isNotSJYPChengban()) {
            this.decision = this.decisions[i].decisionId
          }
          console.log('⭕️⭕️⭕️⭕️' + this.decisions[i].decisionId)
          this.getOrgAndUser(this.decisions[i])
        }
      }
    },

    // 根据所选决策项选择部门或者人（在本页面调取选人接口：如果只有一个人默认展示，否则跳页面选择人）
    getOrgAndUser(appDecision) {

      Toast.loading({ message: "加载中...", forbidClick: false });
      this.normalDecision = appDecision
      this.getUserParams.body = appDecision
      if (this.otherParams&&this.otherParams!=null){
        this.getUserParams.body.otherParams = this.otherParams
      }
      getSrqrRequest(this.getUserUrl, this.getUserParams)
        .then((res) => {
          Toast.clear();
          if (res.data.data && res.data.data.length > 0) {
            if ((this.decision == 'end'&&!this.isNotSJYPChengban()) || (this.decision.indexOf('end') > -1)&& res.data.data[0].user==null ) {
              this.selectData = {
                treeType: res.data.data[0].display,
                group: res.data.data[0].group,
                value: ''
              }
            } else {
              if (res.data.data[0].user && res.data.data[0].user.length > 0) {
                var resUser = res.data.data[0].user
                var uList = [] // 人
                var oList = [] // 组织
                var ouObj = {} // 组织对象
                for (var i in resUser) {
                  if (resUser[i].treeType == 'user') {
                    uList.push(resUser[i])
                  }
                  if (resUser[i].treeType == 'org') {
                    oList.push(resUser[i])
                    ouObj[resUser[i].id] = resUser[i]
                  }
                }
                Toast.clear();
                if (uList.length == 1) {
                  this.uListName = uList[0].name + "123"
                  this.selectData = uList[0]
                  this.selectData.group = res.data.data[0].group
                  this.params.appDecision = appDecision
                } else {
                  // 跳页面选人,先判断是否需要特殊选人
                  var pmInsType = this.getDecisionsParams.kv.processType;
                  var workItemName = this.getDecisionsParams.kv.workItemName;
                  var isNeedDict = false
                  if (pmInsType == 'SQBF' && appDecision.decisionName == '转办') {
                    isNeedDict = true
                  }
                  else if (pmInsType == 'XC'||pmInsType == 'FAZC'||pmInsType == 'FAZCZK') {
                    if (this.getDecisionsParams.belongCompanyTypeDictValue == '01' && (appDecision.decisionName == '转办' || appDecision.decisionName == '同意,请办理' || appDecision.decisionName == '同意,请领导审批' || appDecision.decisionName == '请项目支撑室承办')) {
                      isNeedDict = true
                    } else if (this.getDecisionsParams.belongCompanyTypeDictValue == '02' && (appDecision.decisionName == '转办' || appDecision.decisionName == '同意,请办理')) {
                      isNeedDict = true
                    } else if (this.getDecisionsParams.belongCompanyTypeDictValue == '03' && (appDecision.decisionName == '转办' || appDecision.decisionName == '同意,请办理' || appDecision.decisionName == '同意,请领导审批')) {
                      isNeedDict = true
                    }
                  } else if ((this.getDecisionsParams.kv.processType == 'MH'
                    || this.getDecisionsParams.kv.processType == 'MG'
                    || this.getDecisionsParams.kv.processType == 'MI'
                    || this.getDecisionsParams.kv.processType == 'MJ'
                    || this.getDecisionsParams.kv.processType == 'MK'
                    || this.getDecisionsParams.kv.processType == 'ML') && appDecision.decisionName == '请交付经理主管审批') {
                    isNeedDict = true
                  }
                  else if (pmInsType == 'SJXY' && appDecision.decisionName == '转办') {//商机响应转办
                      isNeedDict = true
                  }
                  else if (pmInsType == 'MD' || pmInsType == 'ME' || pmInsType == 'MF') {

                    if ((appDecision.decisionId == 'dict.managerGradeToLeader')) {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'XE') {

                    if (workItemName == '同意,请政企部审批(市公司)' &&
                      appDecision.decisionName == '同意,请领导审批') {
                      isNeedDict = true
                    }

                    if (appDecision.decisionName == '同意,请办理' ||
                      appDecision.decisionName == '转办' ||
                      appDecision.decisionName == '请项目支撑室承办') {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'XFFB' || pmInsType == 'XFFA' || pmInsType == 'XFF' || pmInsType == 'XF'||pmInsType == 'PF'||pmInsType == 'PT'||pmInsType == 'PZ') {
                    if (appDecision.decisionName == '同意,请办理' ||
                      appDecision.decisionName == '转办' ||
                      appDecision.decisionName == '同意,请领导审批' ||
                      appDecision.decisionName == '请项目支撑室承办') {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'XU') {
                    /// 立项申请
                    if (appDecision.decisionName == '同意,发起会签' ||
                      appDecision.decisionName == '转办') {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'PK' || pmInsType == 'PL') {
                    /// 二次谈判
                    if (appDecision.decisionName == '转办') {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'ZM' || pmInsType == 'ZN') {
                    /// 项目售前支撑 
                    if (appDecision.decisionName == '转办' ||
                      appDecision.decisionName == '请项目支撑室承办' ||
                      appDecision.decisionName == '同意,请领导审批') {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'PO' || pmInsType == 'PP') {
                    /// 合作伙伴甄选公示审批
                    if (appDecision.decisionName == '转办') {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'XN'||pmInsType == 'XNB' || pmInsType == 'XM' || pmInsType == 'XMA' || pmInsType == 'XP') {
                    console.log(pmInsType + '````````````````' + appDecision.id)
                    /// XM应标管理 XN开标 XP签约确认共用
                    if (appDecision.decisionId == 'dict.secondAdminToTurn' ||
                      appDecision.decisionId == 'dict.threeAdminToLead' ||
                      appDecision.decisionId == 'dict.oneAdminTurn' ||
                      appDecision.decisionId == 'dict.leadToManagementLead' ||
                      appDecision.decisionId == 'dict.departmentInteriorToLead' ||
                      appDecision.decisionId == 'dict.startToSecondAdminTrun' ||
                      appDecision.decisionId == 'dict.departmentInteriorToAdmin' ||
                      appDecision.decisionId == 'dict.secondAdminToDepartmentInterior' ||
                      appDecision.decisionId == 'dict.specialLeadToSecondAdminTrun' ||
                      appDecision.decisionId == 'dict.startSpecialToIndustry' ||
                      appDecision.decisionId == 'dict.startSpecialToIndustryLead' ||
                      appDecision.decisionId == 'dict.supportSpecial' ||
                      appDecision.decisionId == 'dict.startNoBelong') {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'XB'||pmInsType == 'YBZC'||pmInsType == 'YBZCZK') {
                    console.log(pmInsType + '````````````````' + appDecision.id)
                    /// XB应标支撑
                    if (appDecision.decisionId == 'dict.startToSupportAssign' ||
                      appDecision.decisionId == 'dict.supportSpecial'||
                      appDecision.decisionId == 'dict.supportAssignToLeadership' ) {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'ZO'||pmInsType == 'ZP'||pmInsType == 'ZR'||pmInsType == 'ZS') {
                    console.log(pmInsType + '````````````````' + appDecision.id)
                    //售中任务申请县ZO、省ZP
                    //通用任务申请县ZR、省ZS
                    if (appDecision.decisionId == 'dict.startTothreeLevelManager'
                      ||appDecision.decisionId == 'dict.enterpriseDepCityToLeader'
                      ||appDecision.decisionId == 'dict.enterpriseDepProvinceToLeader'
                      ||appDecision.decisionId == 'dict.startToCountyLeadership'
                      ||appDecision.decisionId == 'dict.countyToEnterpriseDepCity') {
                      isNeedDict = true
                    }
                  }
                  else if (pmInsType == 'APC' && appDecision.decisionName == '转办') {
                    console.log(pmInsType + '````````````````' + appDecision.id)
                    // //项目变更
                    // if (appDecision.decisionId == 'dict.startToDirecto'
                    //   ||appDecision.decisionId == 'dict.directoToAdmin'
                    //   ||appDecision.decisionId == 'dict.adminToLead'
                    //   ||appDecision.decisionId == 'dict.startToCountyLeadership') {
                      isNeedDict = true
                    // }
                  }else if (pmInsType == 'XKN') {
                    /// 大单奖励流程
                    if (appDecision.decisionName == '请项目支撑室承办') {
                      isNeedDict = true
                    }
                  }
                  else if ((pmInsType == 'ZZ'||pmInsType == 'ZY')&&(appDecision.decisionId == 'dict.startToCityLeader')) {
                    //项目终止申请流程
                    isNeedDict = true
                  }
                  console.log('333333333333333333' + isNeedDict)
                  console.log('AAAAAAA' + isNeedDict + appDecision.decisionId + pmInsType);
                  if (isNeedDict == true) {
                    console.log('44444444444444444444')
                    this.$router.push({
                      name: 'getOrgAndUserDict',
                      query: {
                        type: this.params.type,
                        applyType: this.params.applyType,
                        location: this.params.location,
                        processInstId: this.params.processInstId,
                        processDefName: this.params.processDefName,
                        workItemId: this.params.workItemId,
                        drawUpType: this.params.drawUpType,
                        appDecision: this.normalDecision,
                        currentDecision: this.decisionRadio,
                        formData: this.params.formData,
                        isCopy: 'false',
                        oldParams: this.params,
                        peopledata: res.data,
                        selectPeople: this.selectData,
                        title: '选择审批人'
                      }
                    })
                  }
                  else {
                    console.log('555555555555')

                    this.$router.push({
                      name: 'getOrgAndUser',
                      query: {
                        type: this.params.type,
                        applyType: this.params.applyType,
                        location: this.params.location,
                        processInstId: this.params.processInstId,
                        processDefName: this.params.processDefName,
                        workItemId: this.params.workItemId,
                        drawUpType: this.params.drawUpType,
                        appDecision: this.normalDecision,
                        currentDecision: this.decisionRadio,
                        formData: this.params.formData,
                        isCopy: 'false',
                        oldParams: this.params,
                        peopledata: res.data,
                        selectPeople: this.selectData,
                        title: '选择审批人'
                      }
                    })
                  }

                }
              } else {
                console.log('3333')
                Toast.clear();
                Notify({
                  type: 'warning',
                  message: '当前决策项下无数据，请选择其他决策项',
                  duration: 1300
                })
              }
            }
          }else {
            Toast.clear();
            if(res.message){
              Notify({
                type: 'warning',
                message: res.message,
                duration: 1300
              })
            }else {
              Notify({
                type: 'warning',
                message: '当前决策项下无数据，请选择其他决策项',
                duration: 1300
              })
            }
          }
        }).catch((err) => {
          Toast.clear();
          console.log(err.message)
        })
    },

    // 选择抄送人员
    toSelectCopy() {
      Toast.loading({
        message: "加载中...",
        forbidClick: false,
      });
      this.getUserParams.body = this.copyDecision
      if (this.otherParams&&this.otherParams!=null){
        this.getUserParams.body.otherParams = this.otherParams
      }
      getSrqrRequest(this.getUserUrl, this.getUserParams)
        .then((res) => {
          console.log('44444')
          Toast.clear();
          if (res.data.data && res.data.data.length > 0) {
            if (res.data.data[0].user && res.data.data[0].user.length > 0) {
              var resUser = res.data.data[0].user
              var uList = [] // 人
              var oList = [] // 组织
              var ouObj = {} // 组织对象
              for (var i in resUser) {
                if (resUser[i].treeType == 'user') {
                  uList.push(resUser[i])
                }
                if (resUser[i].treeType == 'org') {
                  oList.push(resUser[i])
                  ouObj[resUser[i].id] = resUser[i]
                }
              }
              if (uList.length == 1) {
                this.copyList = uList
              } else {
                // 跳页面选人
                this.$router.push({
                  name: 'getOrgAndUser',
                  query: {
                    type: this.params.type,
                    applyType: this.params.applyType,
                    location: this.params.location,
                    processInstId: this.params.processInstId,
                    processDefName: this.params.processDefName,
                    workItemId: this.params.workItemId,
                    drawUpType: this.params.drawUpType,
                    appDecision: this.normalDecision,
                    currentDecision: this.decisionRadio,
                    formData: this.params.formData,
                    isCopy: 'true',
                    oldParams: this.params,
                    peopledata: res.data,
                    selectPeople: this.selectData,
                    title: '选择审批人'
                  }
                })
              }
            } else {
              Notify({
                type: 'warning',
                message: '抱歉，暂无抄送人员可供选择',
                duration: 1300
              })
            }
          }
        })

    },

    // 提交
    submitClick(e) {
      if (this.message == '') {
        Notify({ type: 'warning', message: '请填写审批意见', duration: 2500 })
      } else if (!this.selectData && this.decision != 'end') {
        Notify({
          type: 'warning',
          message: '请选择办理人员或部门',
          duration: 1300
        })
      } else {
        var pmInsType = this.getDecisionsParams.kv.processType;
        console.log("pmInsType222222: " +JSON.stringify(this.selectData))
        if ((pmInsType == 'ARZ'||pmInsType == 'ARS'||pmInsType == 'ARX')&&this.selectData&&this.selectData.value) {
          this.verifyPersonDepartmentExists();
        }else {
          // 执行提交
          // Notify({ type: 'warning', message: 'qutijiao', duration: 2500 })
          this.goNext()
        }
      }
    },
    verifyPersonDepartmentExists(){
      Toast.loading({
        message: "加载中1111...",
        forbidClick: false,
      });
      var yanzhengParams = {}
      yanzhengParams.body = {};
      yanzhengParams.kv = {};
      yanzhengParams.kv.currentUserCode=this.getDecisionsParams.kv.currentUserCode
      yanzhengParams.kv.source='MOBILE'
      yanzhengParams.body.amount=this.getDecisionsParams.kv.amount;
      if (this.selectData.length > 0) {
        var vh = []
        for (var i in this.selectData) {
          vh.push(this.selectData[i].id)
        }
        yanzhengParams.body.nextUserName = [
          {
            display: 'orguser', // 暂时先定只有会签是多个人，先将这个写死
            group: this.selectData[0].group,
            value: vh.join(',')
          }
        ]
      } else {
        yanzhengParams.body.nextUserName = [
          {
            display: this.selectData.treeType,
            group: this.selectData.group,
            value: this.selectData.id
          }
        ]
      }
      yanzhengParams.body.outcome=this.params.appDecision.decisionId;
      yanzhengParams.body.pmInsType=this.getDecisionsParams.kv.processType;
      yanzhengParams.body.taskDefinitionKey=this.getDecisionsParams.kv.location;
      verifyPersonDepartmentExists('decisionAndUserNew$api$verifyPersonDepartmentExists', yanzhengParams)
        .then((res) => {
          Toast.clear()
          this.isSubmit = false
          if (res.data.errcode == 0) {
            if (res.data.data&&res.data.data.signStatus==true) {
              // 执行提交
              this.goNext()
            }else if (res.data.data&&res.data.data.signStatus==false) {
              // 执行提交 
              Dialog.alert({ title: "提示", message: "会签环节需要选择财务部人员" }).then(() => { });
            }else {
              Notify(res.message);
            }
          } else {
            Notify(res.message);
          }
        })
        .catch((error) => {
          this.isSubmit = false
          Notify({ type: 'warning', message: '提交失败,请稍后重试' })
        })
    },
    async goNext() {
      Toast.loading({
        message: "加载中...",
        forbidClick: false,
      });
      this.isSubmit = true
      var submitParams = {}
      if (
          this.params.isCopy &&
          this.params.isCopy == 'true' &&
          this.copyList.length > 0
      ) {
        submitParams.outcome = this.params.appDecision.decisionId
        submitParams.copyLocation = this.copyDecision.decisionId
      } else {
        if (this.decision == 'end' || this.decision.indexOf('end') > -1) {
          // 审批归档
          if (this.decision == 'end') {
            submitParams.outcome = 'end'
          }
          if (this.decision.indexOf('end') > -1) {
            submitParams.outcome = this.decision
          }
        } else {
          submitParams.outcome = this.params.appDecision.decisionId
        }
        submitParams.copyLocation = ''
      }
      // submitParams.source = this.params.source;
      // this.$store.state.user.user.username
      submitParams.currentUserCode = this.user.username
      // 流程审批提交多三个字段

      // if (this.params.type) {
      //   if (this.params.type == 'toRead') {
      //     console.log("1111111",this.params.notificationId+"AAAAAA")
      //     submitParams.notificationId = this.params.notificationId
      //   } else {
      //     submitParams.workItemId = this.params.workItemId
      //   }
      //   submitParams.processInstId = this.params.processInstId
      //   submitParams.location = this.params.location
      // }
      // 请求体里的对象
      var flowParam2 = {
        flowParam: {}
      }
      if (
          this.params.isCopy &&
          this.params.isCopy == 'true' &&
          this.copyList.length > 0
      ) {
        // 提交的抄送人数据
        var cList = []
        for (var i in this.copyList) {
          let a = this.copyList[i].id + '-' + this.copyList[i].name
          cList.push(a)
        }
        var cstr = cList.join(',')
        flowParam2.flowParam.copyMessage = '请阅示'
        flowParam2.flowParam.copyNextUserNames = [
          {
            display: this.copyList[0].treeType,
            group: this.copyList[0].group,
            value: cstr
          }
        ]
      } else if (this.params.type == 'toRead') {
        flowParam2.flowParam.copyMessage = this.message
        flowParam2.flowParam.copyNextUserNames = [
          {
            display: this.selectData.treeType,
            group: this.selectData.group,
            value: this.selectData.id
          }
        ]

      } else {
        flowParam2.flowParam.copyMessage = ''
        flowParam2.flowParam.copyNextUserNames = []
      }
      if (
          this.params.isCopy &&
          this.params.isCopy == 'true' &&
          this.copyList.length > 0
      ) {
        flowParam2.flowParam.decisionId = this.copyDecision.decisionId
      } else {
        if (this.decision == 'end' || this.decision.indexOf('end') > -1) {
          if (this.decision == 'end') {
            flowParam2.flowParam.decisionId = 'end'
          }
          if (this.decision.indexOf('end') > -1) {
            flowParam2.flowParam.decisionId = this.decision
          }
        } else {
          flowParam2.flowParam.decisionId = this.params.appDecision.decisionId
        }
      }
      flowParam2.flowParam.formData = this.params.formData
      flowParam2.flowParam.message = this.message
      flowParam2.flowParam.outcomeName = this.decisionName
      if (this.selectData) {
        // 由于决策项出人接口可能会有问题，所以我们先判断是否存在
        if (this.selectData.length > 0) {
          // 需要会签，会签是选多个组织（其实还是对应的多个人）
          var vh = []
          for (var i in this.selectData) {
            vh.push(this.selectData[i].id)
          }
          flowParam2.flowParam.nextUserName = [
            {
              display: 'orguser', // 暂时先定只有会签是多个人，先将这个写死
              group: this.selectData[0].group,
              value: vh.join(',')
            }
          ]
        } else if (this.params.type == 'toRead') {
          flowParam2.flowParam.copyMessage = ''
          flowParam2.flowParam.copyNextUserNames = []
        } else {
          // 选的是单个人
          flowParam2.flowParam.nextUserName = [
            {
              display: this.selectData.treeType,
              group: this.selectData.group,
              value: this.selectData.id
            }
          ]
        }
        submitParams.flowParam = flowParam2
        submitParams.outcomeName = this.message
        this.tosubmintParams.kv.outcome = submitParams.outcome
        this.tosubmintParams.kv.outcomeName = submitParams.outcomeName
        this.tosubmintParams.body = submitParams.flowParam
        console.log("⭕️⭕️⭕️⭕️⭕️⭕️⭕️⭕️⭕️⭕️⭕️⭕️⭕️⭕️⭕️")
        console.log(this.tosubmintParams)
        await util.createOperation('审批', "dict", "")
        getSrqrRequest(this.tosubmintUrl, this.tosubmintParams)
            .then((res) => {
              console.log('66666')
              Toast.clear()
              this.isSubmit = false
              if (res.data.errcode == 0) {
                if (this.params.fromMoa) {
                  this.moaBridge_ha_djfupt.closeDoc({
                    refresh: true,
                    appcode: "dict",
                  });
                } else {
                  Notify({type: 'success', message: '提交成功'})
                  this.$router.replace({path: '/tabview'});
                }

              } else {
                Notify(res.message);
              }
            }).catch((error) => {
          this.isSubmit = false
          Notify({type: 'warning', message: '提交失败,请稍后重试'})
        })

        // if (this.params.processType == 'C') {
        //   gzStartSubmitModifyProcess(submitParams)
        // .then((res) => {
        //   this.isSubmit = false
        //   this.$router.replace({ path: '/home' })
        // })
        // .catch((error) => {
        //   this.isSubmit = false
        //   Notify({ type: 'warning', message: '提交失败,请稍后重试' })
        // })
        // } else {
        //   gzStartSubmitProcess(submitParams)
        //     .then((res) => {
        //       this.isSubmit = false
        //       this.$router.replace({ path: '/home' })
        //     })
        //     .catch((error) => {
        //       this.isSubmit = false
        //       Notify({ type: 'warning', message: '提交失败,请稍后重试' })
        //     })
        // }
      } else {
        this.isSubmit = false
        Notify({type: 'warning', message: '流程异常,请联系管理员'})
      }
      if (localStorage.getItem('history')) {
        localStorage.removeItem('history')
      }
    }
  },
  destroyed() {
    console.log('销毁页面');
    localStorage.setItem('checkboxResultItem', "");
    localStorage.setItem('selectListItem', "");
  }
}
</script>
<style scoped>
.border-b-1 {
  border-bottom: 1px solid #eee;
}

.ht40 {
  width: 100%;
  height: 50px;
  line-height: 50px;
  padding-left: 16px;
  border-bottom: 1px solid #eee;
}

.addOp {
  width: 100%;
  height: 40px;
  line-height: 40px;
  padding-left: 16px;
  font-size: unset;
  display: flex;
}

.bge {
  width: 100%;
  height: 5px;
  background: #eee;
}

.decisionList {
  width: 100%;
}

.ht46 {
  height: 46px;
  line-height: 46px;
}

.pof-btn {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
}

.copyDiv {
  width: 100%;
  padding: 16px;
}

.van-button--default {
  color: #fff;
  background-color: #7abcf8;
  border: 1px solid #ebedf0;
}
</style>
